package com.jd.ymcc.mq;

import com.jd.ymcc.domain.MediaFile;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class CourseVideoProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    public boolean sendMessage(MediaFile mediaFile){
        //1.创建一个message对象。将参数传入
        MessageBuilder<MediaFile> messageBuilder = MessageBuilder.withPayload(mediaFile);
        //2.发送同步消息，获取返回值
        SendResult sendMessage = rocketMQTemplate.syncSend("topic-coursevideo:tag-push:tag-push", messageBuilder);
        //3.获取返回状态，判断是否成功
        SendStatus sendStatus = sendMessage.getSendStatus();
        return SendStatus.SEND_OK == sendStatus?true:false;
    }
}
